"""
演示捕获异常
"""

# 基本捕获语法
try:
    fr = open("d:/abc.txt", "r", encoding="UTF-8")
except:
    print(f"出现异常了")

# 捕获指定的异常
try:
    print(name)
    # 1 / 0
except NameError as e:
    print(f"出现了异常：{e}，异常类型：{type(e)}")

# 捕获多个异常
try:
    # print(name)
    1 / 0
except (NameError, ZeroDivisionError) as e:
    print("出现了变量未定义 或 除以0的异常错误")
    print(f"异常内容：{e}，异常类型：{type(e)}")

# 捕获所有异常
try:
    # fr = open("d:/abc.txt", "r", encoding="UTF-8")
    # 1/ 0
    # print(name)
    print("Hello")
except Exception as e:
    print(f"出现异常了:{e}，异常类型：{type(e)}")
else:
    print("好高兴，没有异常")
finally:
    print("我是finally，有没有异常我都要执行")

print("异常演示完毕")